package com.crazybytex.modbus.beans;

import com.serotonin.modbus4j.ModbusMaster;

/**
 * @Author 程序员潇然 crazybytex.com
 * @Date 2022/8/3 17:22
 * @Description 请求实体封装
 **/
public class ModBusRequest {
    private ModbusMaster modbusMaster;
    private int slaveId;
    private int startOffset;
    private int numberOfRegisters;

    public ModBusRequest(){

    }

    public ModBusRequest(ModbusMaster modbusMaster,int slaveId,int startOffset,int numberOfRegisters){
        this.modbusMaster = modbusMaster;
        this.slaveId = slaveId;
        this.startOffset = startOffset;
        this.numberOfRegisters = numberOfRegisters;
    }

    /**
     * 不设置numberOfRegisters 默认为 1
     * @param modbusMaster
     * @param slaveId
     * @param startOffset
     */
    public ModBusRequest(ModbusMaster modbusMaster,int slaveId,int startOffset){
        this.modbusMaster = modbusMaster;
        this.slaveId = slaveId;
        this.startOffset = startOffset;
        this.numberOfRegisters = 1;
    }

    public ModbusMaster getModbusMaster() {
        return modbusMaster;
    }

    public void setModbusMaster(ModbusMaster modbusMaster) {
        this.modbusMaster = modbusMaster;
    }

    public int getSlaveId() {
        return slaveId;
    }

    public void setSlaveId(int slaveId) {
        this.slaveId = slaveId;
    }

    public int getStartOffset() {
        return startOffset;
    }

    public void setStartOffset(int startOffset) {
        this.startOffset = startOffset;
    }

    public int getNumberOfRegisters() {
        return numberOfRegisters;
    }

    public void setNumberOfRegisters(int numberOfRegisters) {
        this.numberOfRegisters = numberOfRegisters;
    }

    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder("ModBusRequest{");
        sb.append("modbusMaster=").append(modbusMaster);
        sb.append(", slaveId=").append(slaveId);
        sb.append(", startOffset=").append(startOffset);
        sb.append(", numberOfRegisters=").append(numberOfRegisters);
        sb.append('}');
        return sb.toString();
    }
}
